package com.guanglan.serviceImpl;

import com.guanglan.entity.SysUser;
import com.guanglan.mapper.SysUserMapper;
import com.guanglan.service.SysUserService;
import com.guanglan.utils.CreatePassWordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * 作者: 光蓝Comet
 * Date: 2018-06-20 15:34
 * Description: 一句话说明这个类的作用
 * Since 1.0
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return sysUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SysUser sysUser) {
        return sysUserMapper.insert(sysUser);
    }

    public int insertSelective(SysUser sysUser) {
        //密码加盐进行1024次MD5加密
        String salt = String.valueOf((int)(Math.random()*1000000+1));
        sysUser.setSalt(salt);
        sysUser.setPassWord(CreatePassWordUtil.getPwd(sysUser.getPassWord(), salt));
        return sysUserMapper.insertSelective(sysUser);
    }

    @Override
    public SysUser selectByPrimaryKey(Long id) {
        return sysUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SysUser sysUser) {
        return sysUserMapper.updateByPrimaryKeySelective(sysUser);
    }

    @Override
    public int updateByPrimaryKey(SysUser sysUser) {
        return sysUserMapper.updateByPrimaryKey(sysUser);
    }

    @Override
    public SysUser selectSysUserByUserName(String userName) {
        SysUser user = sysUserMapper.selectSysUserByUserName(userName);
        return user;
    }

    @Override
    public List<SysUser> selectSysUsers(String userName, String userPhone) {
        return sysUserMapper.selectSysUsers(userName,userPhone);
    }
}
